<%@page import="orm.Items"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="hibernatelogic.HibItems"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%
	HttpSession sess = request.getSession();

	if (sess.isNew()) {
		response.sendRedirect("/my-pet-project-0/Login.jsp");
	} else {
%>
<%
	if (((String) sess.getAttribute("UserRole")).equals("2")) {
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<a href="/my-pet-project-0/Login.jsp">Logout</a>
	<a href="/my-pet-project-0/ManagerStartPage.jsp">Back</a>
	<br>
	<br>
	<center>Fill the form to input new item</center>
	<br>
	<br>
	<center>
		<form action="add-new-item" method="post" name="addform">
			ITEM NAME: <br> <input type="text" name="nname" maxlength="40">
			<br> ITEM PRICE: <br> <input type="text" name="nprice">
			<br> <br> <br> <input type="submit"
				value="Add an item" onclick="return CheckFields()">
		</form>
	</center>
	<script language="javascript" type="text/javascript">
		function CheckFields(){
			if(document.forms.addform.nname.value !=""){
				
			} else {
				alert("Please, enter the ITEM NAME");
				document.forms.addform.nname.focus();
				return false;
			}
			if(document.forms.addform.nprice.value !=""){
				valid_chars = "1234567890";
				str = document.forms.addform.nprice.value;
				valid_string = true;
				 for(i=0; i < str.length; i++ ) 
			     { 
			       current_valid_char = false; 
			       for(j=0; j < valid_chars.length; j++) 
			         { 
			           if(str.charAt(i) == valid_chars.charAt(j)) 
			             { 
			               current_valid_char = true; 
			             } 
			         } 
			       if(current_valid_char == false) 
			         { 
			          valid_string = false; 
			         }
			       if(current_valid_char == false && i == (str.length - 1)) 
			         { 
			          alert("only numeric values"); 
			         }
			     }
			     return valid_string;
			} else {
				alert("Please, enter the PRICE");
				document.forms.addform.nprice.focus();
				return false;
			}
		}
	</script>
</body>
</html>
<%
	} else {
%>
<%
	response.sendError(response.SC_FORBIDDEN,
					"Not permitted to enter as MANAGER");
%>
<%
	}
	}
%>